import React, { Component, useState, useRef, useEffect } from 'react'
import { Tabs, Form, Input, Checkbox, Button, Row, Col, Modal, message } from 'antd'
import { AndroidOutlined, IdcardOutlined, UserOutlined, LockOutlined } from '@ant-design/icons';
import "./index.scss"
const { TabPane } = Tabs;
export default function LoginIndex({
    history
}) {
    return (
        <div className='login'>
            <video
                src={require('../../assets/images/mv.mp4').default}
                className='myvideo'
                autoPlay
                loop
                playsInline
                muted
            ></video>
            <div className="login-box">
                <Tabs defaultActiveKey="1">
                    <TabPane
                        tab={
                            <span>
                                <IdcardOutlined />
                                    账号登陆
                                </span>
                        }
                        key="1"
                    >
                        <PassLogin history={history}></PassLogin>
                    </TabPane>
                    <TabPane
                        tab={
                            <span>
                                <AndroidOutlined />
                                    验证码登录
                                </span>
                        }
                        key="2"
                    >
                        <CaptchaLogin history={history}></CaptchaLogin>
                    </TabPane>
                </Tabs>,
            </div>
        </div>
    )
}


const layout = {
    labelCol: { span: 8 },
    wrapperCol: { offset: 2, span: 20 },
};
export const PassLogin = () => {
    const [isModalVisible, seyIsModalVisible] = useState(false)
    const myform = useRef()
    const telphone = useRef()
    const onFinish = () => {

    }
    const onFinishFailed = () => {

    }
    const Control = () => {

    }
    const handleOk = () => {

    }
    const handleCancel = () => {

    }
    return (
        <div>
            <Form
                {...layout}
                autoComplete='off'
                name="normal_login"
                className="login-form"
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
                ref={myform}
            >
                <Form.Item
                    name="username"
                    rules={[
                        { required: true, message: 'Please input your Username!' }]}
                >
                    <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="Username" />
                </Form.Item>
                <Form.Item
                    name="password"
                    rules={[{ required: true, message: 'Please input your Password!' }]}
                >
                    <Input
                        prefix={<LockOutlined className="site-form-item-icon" />}
                        type="password"
                        placeholder="Password"
                    />
                </Form.Item>
                <Form.Item>
                    <Picture></Picture>
                </Form.Item>

                <Form.Item>
                    <Form.Item name="remember" valuePropName="checked" noStyle>
                        <Checkbox>记住密码</Checkbox>
                    </Form.Item>

                    <span style={{ cursor: 'pointer' }} className="login-form-forgot" onClick={Control}>
                        忘记密码
                </span>
                </Form.Item>

                <Form.Item>
                    <Button type="primary" block round='true' htmlType="submit" className="login-form-button">
                        登录
                </Button>
                </Form.Item>
                <a className='register' href="">register now!</a>
            </Form>

            <Modal title="Basic Modal" visible={isModalVisible} title='找回密码' okText='下一步' onOk={handleOk} onCancel={handleCancel}>
                <p>请输入你要找回密码的手机号</p>
                <Input
                    ref={telphone}
                    type="text"
                    placeholder="Please enter your phone...."
                />
            </Modal>
        </div>
    )
}
export const Picture = () => {
    const mycanvas = useRef()
    console.log(mycanvas);
    // var context = canvas.getContext("2d");//舞台，getContext() 方法可返回一个对象，该对象提供了用于在画布上绘图的方法和属性。
    // console.log(context);
    // var button = document.getElementById("bt");//获取按钮
    // var input = document.getElementById("text");//获取输入框
    // draw();
    // canvas.onclick = function () {
    //     context.clearRect(0, 0, 120, 40);//在给定的矩形内清除指定的像素
    //     draw();
    // }
    // // 随机颜色函数
    // function getColor() {
    //     var r = Math.floor(Math.random() * 256);
    //     var g = Math.floor(Math.random() * 256);
    //     var b = Math.floor(Math.random() * 256);
    //     return "rgb(" + r + "," + g + "," + b + ")";
    // }
    // function draw() {
    //     context.strokeRect(0, 0, 120, 40);//绘制矩形（无填充）
    //     var aCode = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
    //     // 绘制字母
    //     var arr = [] //定义一个数组用来接收产生的随机数
    //     var num //定义容器接收验证码
    //     for (var i = 0; i < 4; i++) {
    //         var x = 20 + i * 20;//每个字母之间间隔20
    //         var y = 20 + 10 * Math.random();//y轴方向位置为20-30随机
    //         var index = Math.floor(Math.random() * aCode.length);//随机索引值
    //         var txt = aCode[index];
    //         context.font = "bold 20px 微软雅黑";//设置或返回文本内容的当前字体属性
    //         context.fillStyle = getColor();//设置或返回用于填充绘画的颜色、渐变或模式，随机
    //         context.translate(x, y);//重新映射画布上的 (0,0) 位置，字母不可以旋转移动，所以移动容器
    //         var deg = 30 * Math.random() * Math.PI / 180;//0-90度随机旋转
    //         context.rotate(deg);// 	旋转当前绘图
    //         context.fillText(txt, 0, 0);//在画布上绘制“被填充的”文本
    //         context.rotate(-deg);//将画布旋转回初始状态
    //         context.translate(-x, -y);//将画布移动回初始状态
    //         arr[i] = txt //接收产生的随机数
    //     }
    //     num = arr[0] + arr[1] + arr[2] + arr[3] //将产生的验证码放入num
    //     // 绘制干扰线条
    //     for (var i = 0; i < 8; i++) {
    //         context.beginPath();//起始一条路径，或重置当前路径
    //         context.moveTo(Math.random() * 120, Math.random() * 40);//把路径移动到画布中的随机点，不创建线条
    //         context.lineTo(Math.random() * 120, Math.random() * 40);//添加一个新点，然后在画布中创建从该点到最后指定点的线条
    //         context.strokeStyle = getColor();//随机线条颜色
    //         context.stroke();// 	绘制已定义的路径
    //     }
    //     // 绘制干扰点，和上述步骤一样，此处用长度为1的线代替点
    //     for (var i = 0; i < 20; i++) {
    //         context.beginPath();
    //         var x = Math.random() * 120;
    //         var y = Math.random() * 40;
    //         context.moveTo(x, y);
    //         context.lineTo(x + 1, y + 1);
    //         context.strokeStyle = getColor();
    //         context.stroke();
    //     }

    //点击按钮验证
    // button.onclick = function () {
    //     var text = input.value //获取输入框的值
    //     if (text === num) {
    //         alert('验证通过')
    //     } else {
    //         alert('验证失败')
    //     }
    // }
    return (
        <div>
            <canvas id='canvas' ref={mycanvas} width="120" height="40"></canvas>
            <input id="text" />
        </div>
    )
}





const layout2 = {
    labelCol: { offset: 1, span: 4 },
    wrapperCol: { offset: 1, span: 16 },
};
const tailLayout = {
    wrapperCol: { offset: 3, span: 19 },
};
export const CaptchaLogin = () => {
    const [flag, setFlag] = useState(false)
    const [word, setWord] = useState('获取验证码')
    const inp = useRef()
    const onFinish = () => {

    }
    const handle = () => {

    }
    const getCaptcha = () => {

    }
    return (
        <div>
            <Form
                id='captcha'
                {...layout2}
                autoComplete='off'
                name="normal_login"
                className="login-form"
                initialValues={{ remember: true }}
                onFinish={onFinish}
                ref={inp}
            >
                <Form.Item
                    name="phone"
                    label="手机号"
                    rules={[
                        { required: true, message: 'Please input your nickname!', whitespace: true }
                    ]}
                >
                    <Input onChange={() => handle()} />
                </Form.Item>
                <Form.Item label="验证码">
                    <Row gutter={8}>
                        <Col span={12}>
                            <Form.Item
                                name="captcha"
                                noStyle
                                rules={[{ required: true, message: 'Please input the captcha you got!', whitespace: true }]}
                            >
                                <Input />
                            </Form.Item>
                        </Col>
                        <Col span={12}>
                            <Button disabled={flag} type='danger' onClick={getCaptcha}>{word}</Button>
                        </Col>
                    </Row>
                </Form.Item>

                <Form.Item {...tailLayout} >
                    <Button block type='primary' htmlType="submit">登录</Button>
                </Form.Item>
            </Form>
        </div>
    )
}
